// 测试归并方法

let numbers = [1,2,3,4,5,6,7,8,9,10];
console.log( numbers.length );

let callback = function(previous,current,currentIndex,array){
    console.log( previous, current );
    return previous + current ;
}

// Array.prototype.reduce( fn ) 
let sum = numbers.reduce( callback ) ;
console.log( sum );

// Array.prototype.reduce( fn ) 
let factorial = numbers.reduce( (previous,current) => previous * current );
console.log( factorial );

sum = numbers.reduceRight( (accumulator, current)=> accumulator + current );
console.log( sum );